@form-half-width: 540px;
@form-margin: 12px;
@form-label-width: 150px;
@form-input-width: @form-half-width - @form-label-width - (@form-margin * 3);
@form-input-width-short: 260px;
@form-icon-size: 16px;
@form-bubble-label-width: @form-label-width;
@form-bubble-input-width: 176px;

.border-radius (@radius) {
  border-radius: @radius;
  -moz-border-radius: @radius;
  -webkit-border-radius: @radius;
}

input { background: #fff; color: @text-black; }
input:-ms-input-placeholder, // IE10
input::-moz-placeholder, // ff 19+
input:-moz-placeholder, // ff 4-18
input::-webkit-input-placeholder { // webkit
    color: @dark-text;
}
input[disabled], input[readonly] { background: @medium-bg; cursor: default; }
input[disabled].lookup-performed { color: @dark-text; }

/* this is to ensure input/select/textarea elements are all the same
   width if you set the same width on them. (without this a <select>
   is a few pixels narrower than an <input type="text> in at least
   firefox and chrome) */
input:not(.gsc-search-button), select, textarea {
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}

button.nobutton:focus,
button.nobutton:hover,
button.nobutton {
    background: transparent;
    color: inherit;
    font-size: inherit;
    font-style: inherit;
    font-family: inherit;
    border: 0;
    padding: 0;
    margin: 0;
}
button.nobutton::-moz-focus-inner { margin: -1px; padding: 0; };

div.various-artists.warning { width: 50em; }

fieldset {
    margin-top: @form-margin;
    margin-bottom: @form-margin;
    border: none;
    padding: 0;
}

fieldset legend { margin-top: 0; }

form, div.form {
    div.row {
        clear: left;
        margin: 6px 0;
    }

    div.row label,
    div.row div.label,
    fieldset.row legend {
        float: left;
        text-align: right;
        min-width: @form-label-width;
        margin-right: @form-margin;
    }

    div.row.no-label label {
        float: none;
    }

    div.row button.icon {
        margin-left: 2px;
        vertical-align: text-top;
    }
}

div.form-row-text-list, div.form-row-select-list {
    margin-left: @form-label-width + @form-margin;

    button > img { vertical-align: middle; }
}

div.form-row-add {
    text-align: right;
    width: @form-input-width + 2;
    margin: (@form-margin / 2) 0;
}

div.form-row-add.short { width: @form-input-width-short; }

/* these rows are missing a <label> on the left and use a margin instead. */
div.form-row-add.nolabel { margin-left: @form-label-width + @form-margin; }

div.form-row-add.nolabel { margin-left: @form-label-width + @form-margin; }

form div.checkbox-block div.row {
    display: inline-block;
    margin-left: 0;
}

.bubble {
    display: none;
    position: absolute;
    min-height: 54px;
    margin: 0;
    padding: @form-margin;
    background: @very-light-bg;
    border-radius: 12px;
    box-sizing: border-box;
    > svg { color: @very-light-bg; }
    > p:first-child { margin-top: 0; }
    > p:last-child { margin-bottom: 0; }
}

.bubble-tail {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
}

.bubble.left-tail:before {
    .bubble-tail();
    right: 100%;
    top: 16px;
    border-top: 12px solid transparent;
    border-right: 18px solid @very-light-bg;
    border-bottom: 12px solid transparent;
}

.bubble.right-tail:after {
    .bubble-tail();
    left: 100%;
    top: 50%;
    top: calc(~"50% - 12px");
    border-top: 12px solid transparent;
    border-left: 18px solid @very-light-bg;
    border-bottom: 12px solid transparent;
}

.bubble div.row input[type=text],
.bubble div.row input[type=email],
.bubble div.row input[type=number],
.bubble div.row input[type=url] {
    width: @form-bubble-input-width;
    font-size: @medium-text;
}

.bubble div.row label,
.bubble div.row div.label { width: @form-bubble-label-width; }

form div.row p { float: none; clear: none; }
form div.row ul { overflow: auto; }

form div.no-label,
div.form div.no-label,
form p.no-label,
form ul.errors {
    margin-left: @form-label-width + @form-margin;
}

form div.no-margin {
    margin-left: 0;
}

.collaborators-form-list {
    div.autocomplete2 { width: @form-input-width-short; }
    ul.errors { margin-left: 0; }
}

.select-list-row ul.errors {
    margin-left: 0;
}

ul.errors {
    margin-top: 4px;
    padding-left: 0;
    list-style-type: none;
    list-style-image: none;
}

ul.errors li, .error { color: @negative-text; }
span.success { color: @positive-text; }

input.error,
select.error {
    color: @text-black;
    background: @negative-bg ! important;
}

input.success,
input.lookup-performed { background: @positive-bg; }

form .input-note {
    font-style: italic;
    font-size: @small-text;
}

.sanitized-password-note {
    color: #F22;
    font-weight: bold;
}

ul.radio-list {
    list-style-type: none;
    list-style-image: none;
    padding: 0;
}

label.required,
div.required {
    font-weight: bold;
}

/* Used to indicate required fields. */
.asterisk {
    content: "*";
    left: -0.75em;
    top: -0.25em;
}

div.required::before {
    position: absolute;
    .asterisk();
}

textarea {
    font-family: sans-serif;
    font-size: @medium-text;
}

label.inline {
    float: none !important;
    width: auto !important;
}

dl.properties label {
    float: none;
    width: auto;
}

div.ar-descr, div.form-help {
    .help-box();
    margin: 6px;
}

div.form-help {
    margin-left: 1.4em;
}

div.searchform {
    margin-top: 24px;
}

#edit-search select[multiple=multiple] {
    resize: vertical;
}

/* <table>-based forms to replace div.row-based stuff. */

table.row-form {
    width: 100%;

    label { display: inline-block; text-align: right; }

    input[type=text], input[type=email], input[type=number], input[type=url], select, span.autocomplete {
        width: 100%;
    }

    > tbody > tr, > thead > tr {
        > td:first-child, > th:first-child {
            min-width: @form-label-width;
            padding: (@form-margin / 2);
            padding-bottom: 9px;
            box-sizing: border-box;
            vertical-align: top;

            label { width: 100%; }
        }
    }

    td {
        &.partial-date { min-width: @form-label-width; }
        &.add-item { text-align: right; }
        &.error { padding-bottom: @form-margin; }
    }

    tr.error td:first-child { padding: 0; }

    ul.errors { margin: 0; }
}

/* __________________________________

          Guess Case
   __________________________________ */

button.guesscase-title, button.guesscase-sortname {
    background-image: data-uri('../images/icons/guesscase.png');
}

button.sortname-copy {
    background-image: data-uri('../images/icons/copy.png');
}

button.guesscase-options {
    background-image: data-uri('../images/icons/cog.png');
}

button.guessfeat {
    background-image: data-uri('../images/icons/guessfeat.png');
    background-size: @form-icon-size @form-icon-size;
}

input[type=text] {
    &.modified { background-color: @input-modified-bg; }
    &.preview { background-color: @input-preview-bg; }
}

/* __________________________________

          MB.Control.Autocomplete
   __________________________________ */

span.autocomplete { display: inline-block; position: relative; }
span.autocomplete img.search {
    height: 16px;
    position: absolute;
    right: 2px;
    top: 3px;
    width: 16px;
}
span.autocomplete.disabled img.search { display: none; }
span.autocomplete input.ui-autocomplete-loading + img.search { display: none; }

.ui-autocomplete-loading {
    background: white data-uri('../images/icons/loading.gif') right center no-repeat;
}

button.autocomplete-pager {
    position: absolute;
    display: block;
    border: 0;
    width: 18px;
    height: 18px;
    background-color: transparent;
}

span.autocomplete-isrcs,
span.autocomplete-appears,
span.autocomplete-comment,
span.autocomplete-video {
    margin-left: @form-margin;
    color: @dark-text;
}

span.autocomplete-length,
span.autocomplete-language {
    color: @very-dark-text;
    float: right;
    margin-left: 2em;
}

/* __________________________________

         Half-width edit forms
   __________________________________ */

div.half-width {
    clear: both;
    float: left;
    margin: @form-margin 0 0 0;
    width: @form-half-width;
}

div.half-width p,
fieldset > p {
    margin: 1em;
}

div.documentation {
    margin-left: @form-half-width + 20;
}

div.half-width fieldset {
    border: 1px solid @light-border;
    margin-top: 0;
    .border-radius(6px);
}

div.half-width fieldset.editnote {
    background-color: inherit;
    border-color: transparent; /* this preserves the spacing below the legend, but keeps the border hidden */
}

div.half-width fieldset legend {
    color: @text-orange;
    font-size: @large-text;
    font-weight: bold;
    margin: 0 10px;
}

div.half-width fieldset label.row {
    float: left;
    margin-right: @form-margin;
    text-align: right;
    width: @form-label-width;
}

div.half-width fieldset label.required {
    font-weight: bold;
}

div.half-width fieldset input,
div.half-width fieldset select {
    font-size: @medium-text;
    width: @form-input-width;
}

div.half-width fieldset input.short,
div.half-width fieldset select.short {
    width: @form-input-width-short;
    font-weight: bold;
}

div.half-width fieldset {
    input.with-button, select.with-button {
        width: @form-input-width - @form-icon-size - 2;
    }

    input.with-guesscase {
        width: @form-input-width - (@form-icon-size * 2) - 6 !important;
    }

    input.with-guesscase-guessfeat {
        width: @form-input-width - (@form-icon-size * 3) - 9 !important;
    }
}

div.half-width fieldset input[type=checkbox] {
    width: auto;
}

span.partial-date,
div.half-width fieldset span.partial-date {
    white-space: nowrap;

    input {
        width: auto;
        &.partial-date-year { width: 4em; }
        &.partial-date-month { width: 2.5em; }
        &.partial-date-day { width: 2.5em; }
    }
}

div.half-width fieldset textarea {
    width: @form-input-width;
}

div.half-width fieldset input.label-code {
    width: 100px;
}

div.half-width fieldset input.time {
    width: 4em;
}

div.half-width fieldset h3 {
    margin: 24px 10px 0;
}

div.documentation div.artist-credit div.row { clear: none; overflow: hidden; }

table.form th,
table.form td{
    vertical-align: top;
}

table.form th {
    text-align: right;
    padding-bottom: 8pt;
    width: 100pt;
}

table.form {
    padding: 10pt 0;
}

ul.conditions button.remove {
    display: none;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
}

ul.conditions button.remove,
button.nobutton {
    cursor: pointer;
}

ul.conditions button.remove img {
    vertical-align: middle;
}

#filter {
    margin-top: 0.75em;
    border: 1px solid @dark-border;
    background: @very-light-bg;
    .border-radius(3px);
    padding: 0.5em;
    ul.errors { margin-left: 0; }
    td:first-child {
        vertical-align: top;
        white-space: nowrap;
    }
}

input.icon, div.icon.img, span.icon.img, button.icon, a.icon {
    min-width: @form-icon-size;
    min-height: @form-icon-size;
    border: 0 !important;
    background-repeat: no-repeat;
    background-color: transparent;
    vertical-align: middle;
    cursor: pointer;
}
input.icon:disabled, button.icon:disabled { cursor: default; }

div.img, button.icon, a.icon { display: inline-block; }

button.with-label {
    border: none;
    background-color: transparent;
    background-position: right;
    background-repeat: no-repeat;
    padding-right: @form-icon-size + 4;
    cursor: pointer;

    &[disabled] {
        cursor: default;
    }
}

button.add-item {
    background-image: data-uri('../images/icons/add_row.svg');
    background-size: 16px;
}

.remove-artist-credit,
a.remove-item,
button.remove-item,
button.close-dialog {
    /* The !important overrides .nobutton:hover. */
    background-image: data-uri('../images/icons/delete_row.svg') !important;
    background-size: 16px;
}

.edit-item {
    background: data-uri('../images/icons/edit.svg');
    background-size: 16px;

    &[disabled] {
        cursor: default;
        opacity: 0.3;
    }
}

.file-down, .track-down, .move-down {
    background-image: data-uri('../images/icons/track-down.png');
}

.file-up, .track-up, .move-up {
    background-image: data-uri('../images/icons/track-up.png');
}

.help {
    background-image: data-uri('../images/icons/help.png');
    cursor: help !important;
}

button.undo {
    background-image: data-uri('../images/icons/arrow_undo.png');
    background-size: 16px;
}

/*
  Artist credits
  ================================================
*/

.open-ac {
    .styled-button();
    padding: 0 1em;
}

.add-artist-credit {
    margin-left: @form-bubble-label-width - @form-margin !important;
    width: @form-bubble-input-width;
    text-align: right;
}

div.artist-credit-editor {
    width: @form-input-width;
}

#artist-credit-bubble {
    background: @very-light-bg;
    max-width: 800px !important;

    #ac-docs, #ac-preview-cell { padding-bottom: 1em; }

    tr.artist-credit-header > th {
        &:nth-child(1), &:nth-child(2) { width: 40%; }
    }

    input[type=text], div.autocomplete2 { width: 100%; }

    .removed-ac-name { text-align: right; }

    button.move-down:disabled, button.move-up:disabled { opacity: 50%; }

    button.remove-artist-credit { margin-left: 0.5em; }

    .buttons {
        #copy-ac, #paste-ac { float: left; }
        #next-track-ac, #prev-track-ac, button.positive { float: right; }
        button.positive { margin-left: 2em; }
        margin-top: 1em;
        width: 100%;
    }
}

/*
  External links editor
*/

#external-links-editor {
    td {
        vertical-align: top;
        padding-top: (@form-margin / 2);

        &:first-child {
            min-width: 30px;
            padding-right: 0;
        }
    }

    td:nth-child(3) {
        width: 100%;
        padding-left: (@form-margin / 4);
    }

    td.link-actions {
        text-align: right;
        min-width: 42px;

        button.remove-item {
            margin: 0 4px !important;
        }
    }

    .external-link-item {
        transition: background-color 0.3s ease-out;
        -moz-transition: background-color 0.3s ease-out;
        -webkit-transition: background-color 0.3s ease-out;

        td {
            padding-bottom: (@form-margin / 4);
        }

        td:first-child {
            text-align: right;
        }

        a.url:focus-visible {
            outline: revert; // reset to UA stylesheet
        }
    }

    .relationship-item {
        td {
            padding-top: (@form-margin / 4);
            padding-bottom: (@form-margin / 4);
        }

        div.relationship-content {
            display: flex;

            label {
                margin-right: (@form-margin / 2);
                white-space: nowrap;
            }

            label.relationship-name {
                flex: 2 5;
                text-align: left;
                white-space: inherit;

                span.date-period {
                    white-space: nowrap;
                }
            }

            select {
                width: auto;
            }

            .attribute-container {
                display: inline-block;
            }
        }
    }

    .add-relationship td {
        padding: 0;
    }
}

#external-links-editor, #work-attributes {
    width: 100%;
    padding: (@form-margin / 2);

    td:first-child select {
        max-width: @form-label-width - @form-margin;
    }

    td.errors ul { margin: 0; }

    input[type=text], input[type=email], input[type=number], input[type=url] { width: 100%; }
}

#work-attributes td:nth-child(2) { width: 100%; }

// For release editor, align with the form above
#release-editor #external-links-editor {
    padding: 0;
}

#external-links-editor span.favicon {
    display: inline-block;
    width: @form-icon-size;
    height: @form-icon-size;
    vertical-align: middle;
    margin-right: 4px;
}

#external-links-editor span.url-quote {
    display: inline-block;
    font-style: italic;
    word-break: break-all;
}

/* Guess user timezone */

button.guess-timezone {
    background-image: data-uri('../images/icons/magnet.png');
}

.dialog {
    width: max-content;
    padding: 1em;
    position: absolute;
    background: @text-white;
    border: 1px solid #AAA;
    top: 0;
    left: 0;
    filter: drop-shadow(2px 2px 4px @very-dark-grey);
    -webkit-filter: drop-shadow(2px 2px 4px @very-dark-grey);

    h1 {
        color: @musicbrainz-orange;
        font-size: @large-text;
        margin-bottom: 1em;
    }

    &.modal {
        max-width: 500px;
        height: 100%;
        display: flex;
        flex-direction: column;

        @media @wide {
            max-width: 700px;
        }

        @media @wide900px {
            max-width: 800px;
        }

        /* Put above jQuery UI's .ui-front (use by the relationship
         * editor dialog), which has a z-index of 100.
         *
         * These can overlap when the "Add a new $entity" option is
         * invoked from the relationship target autocomplete.
         */
        z-index: 200;

        /* Center the modal horizontally. */
        left: 50%;
        transform: translateX(-50%);

        .title-bar {
            display: flex;
            padding: 8px;
            h1 {
                flex-grow: 1;
                margin-bottom: 0em;
            }
            button.close-dialog {
                padding: 4px;
            }
        }

        .dialog-content {
            flex-grow: 1;
        }

        &.iframe-dialog iframe {
            height: 100%;
        }
    }

    &.popover {
        .border-radius(12px);
        > svg { color: @text-white; }
        &#artist-credit-bubble > svg { color: @very-light-bg; }
    }
}

.modal-backdrop {
    background: rgba(0, 0, 0, 0.1);
}

/* root/static/scripts/common/components/PostParameters.js */

.post-parameters {
    a.expand-link {
        display: inline-block;
        padding-bottom: 1em;
    }
    table.all-collapsed {
        display: none;
    }
    input, textarea {
        font-family: sans-serif;
        font-size: @medium-text;
        width: 50ch;
    }
}

/* root/static/scripts/edit/components/DateRangeFieldset.js */
/* root/static/scripts/relationship-editor/components/DialogDatePeriod.js */

button.copy-date {
    background-image: data-uri('../images/icons/down.png');
    margin-left: 4px;
}

/* root/static/scripts/admin/components/PossibleSpammersList.js */

div.possible-spammers {
    table {
        width: 100%;
        table-layout: fixed;

        th, td {
            overflow-wrap: break-word;
        }

        tr.spammer { opacity: 0.5; }

        tr:hover > td {
            background-color: @positive-hover-background !important;
        }
    }
}
